from datetime import datetime

from flask_wtf import FlaskForm

from models.biz_enum import *


class BaseForm(FlaskForm):

    def is_integer(self, value_data):
        try:
            if value_data:
                i_value_data = int(value_data)
                if i_value_data > 0:
                    return True

            return False
        except Exception as e:
            return False

    def get_role_list(self, is_all=False):
        data_source = [(k.value, v) for k, v in AccountRole.to_list()]
        if is_all:
            data_source.insert(0, ('', '全部'))

        return data_source

    def get_module_list(self, is_all=False):
        data_source = [(k.value, v) for k, v in SystemLogModule.to_list()]
        if is_all:
            data_source.insert(0, ('', '全部'))

        return data_source

    def get_dy_sync_status_list(self):
        data_source = [(k.value, v) for k, v in VideoLibraryDySyncStatus.to_list()]
        data_source.insert(0, ('', '全部'))

        return data_source

    def get_release_year_list(self, is_all=False):
        current_year = datetime.now().year
        year_choices = [(str(year), str(year)) for year in range(current_year + 2, 2010, -1)]
        if is_all:
            year_choices.insert(0, ('', '全部'))

        return year_choices

    def get_album_status_list(self, is_all=False):
        data_source = [(k.value, v) for k, v, c in AlbumStatus.to_list()]
        if is_all:
            data_source.insert(0, ('', '全部'))

        return data_source

    def get_qualification_list(self, is_all=False):
        data_source = [(k.value, v) for k, v, c in Qualification.to_list()]
        if is_all:
            data_source.insert(0, ('', '全部'))

        return data_source

    def get_record_type_list(self, is_all=False):
        data_source = [(k.value, v) for k, v, c in RecordType.to_list()]
        if is_all:
            data_source.insert(0, ('', '全部'))

        return data_source

    def get_playlet_production_cost_list(self, is_all=False):
        data_source = [(k.value, v) for k, v, c in PlayletProductionCost.to_list()]
        if is_all:
            data_source.insert(0, ('', '全部'))

        return data_source
